<?php

	class RegisterHandler{
		
		private $db = NULL;			
		
		public function __construct(Database $database){
			$this->db = $database;
		} 		
		
		public function UserNameCompare($userName){
			
			$prep = $this->db->Prepare("SELECT COUNT(*) FROM user WHERE userName=?");
			$prep -> bind_param("s", $userName); 
			$result = $this->db->SelectOne($prep);	
				
			if($result == 1){					
				return false;
			}
			else{
				return true;
			}			
			
		}
		
		public function SaveUser($userName, $passWord){
			
			if($userName == "" || strlen($passWord) < 6){
				return false;
			}
							
			if($this->UserNameCompare($userName)){
				$prep = $this->db->Prepare("INSERT INTO user (userName, password) VALUES (?,?)");
				$prep -> bind_param("ss", $userName, crypt($passWord)); 
				$userID = $this->db->RunInsertQuery($prep);	
								
				return true;
			}
			return false;
			
		}
	}
